import http.client

class Resp:
    def getSessionid(self,host):
        conn = http.client.HTTPConnection(host)
        param = "name=admin&password=123456&verifyCode=aaaa"
        header = {'Content-type':'application/x-www-form-urlencoded','Accept':
            'text/html, application/xhtml+xml, */*'}
        conn.request("POST",'/TinyShop_v2.4/index.php?con=admin&act=login',param,header)
        setcookie = conn.getresponse().getheader("set-cookie")
        sessionid= setcookie.split(";")[0]
        return sessionid
    def httpPost(self,parm):
        session = self.getSessionid(parm[0])
        conn = http.client.HTTPConnection(parm[0])
        header = {'Content-type':'application/x-www-form-urlencoded','Accept':
            'text/html, application/xhtml+xml, */*','Cookie':session}
        conn.request(parm[1],parm[2],parm[3],header)
        status = conn.getresponse().status
        return status
    def API(self,param1,parma2,parm,expect):
        flag = False
        if parm[1] == "POST":
            status = self.httpPost(parm)
        elif parm[1] == "GET":
            pass
        if str(status) == expect[0]:
             flag = True
        return flag
